from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

import time
desire = DesiredCapabilities.PHANTOMJS.copy()
headers = {
    'Accept': '*/*',
    'Accept-Language': 'en-US,en;q=0.8',
    'Cache-Control': 'max-age=0',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
    'Connection': 'keep-alive',
    'Referer':'http://www.baidu.com/'
}
for key,value in headers.items():
        desire['phantomjs.page.customHeaders.{}'.format(key)] = value
obj = webdriver.PhantomJS(desired_capabilities=desire, service_args=['--load-images=yes'])#将yes改成no可以让浏览器不加载图片
obj.implicitly_wait(30)
# obj.set_page_load_timeout(10)
# obj.set_script_timeout(10)#这两种设置都进行才有效
obj.maximize_window()
obj.get('https://zhiyou.smzdm.com/user/login?redirect_to=https://www.smzdm.com/')#请求登陆页面
# obj.save_screenshot("1.png")   #截图保存
# exit()
# J_login_trigger=obj.find_element_by_class_name('J_login_trigger')
# J_login_trigger=obj.find_element_by_xpath("//a[@data-style='login']")
# J_login_trigger.click()
# sleep(10)
# obj.save_screenshot("2.png")   #截图保存
#填写用户名密码
username=obj.find_element_by_id('username')
username.send_keys('18764285761')

password=obj.find_element_by_id('password')
password.send_keys('bangde007')

login_submit=obj.find_element_by_id('login_submit')
login_submit.click()

title=obj.title
print(title)
obj.save_screenshot("1.png")
time.sleep(3)#等待页面加载
obj.refresh()
time.sleep(3)#等待页面加载
J_punch=obj.find_element_by_class_name('J_punch')

J_punch.click()
title=obj.title
print(title)

obj.save_screenshot("2.png")   #截图保存
print('自动签到完成')
